﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using CentralOffice.PublicAffair.Data;
using CentralOffice.PublicAffair.BusinessActions;

using NoticeTable = CentralOffice.PublicAffair.Data.NoticeDataSet.NotificationsDataTable;
using NoticeRow = CentralOffice.PublicAffair.Data.NoticeDataSet.NotificationsRow;

namespace CentralOffice.WebClient.PublicAffairs
{
    public partial class NoticeQuery : PageBase
    {
        private bool? authorized = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                SiteUtil.PopulateListBox(ddlSignificant, SiteConstants.Significant, true);
                
            }

            if (authorized == null)
            {
                authorized = this.Authorize(AuthorizationRules.Notice_Delete);
            }
            if (!authorized.Value)
            {
                gvNotice.Columns.RemoveAt(3);
                gvNotice.Columns.RemoveAt(3);
            }
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            gvNotice.PageIndex = 0;

            NoticeRow notice = (new NoticeDataSet()).Notifications.NewNotificationsRow();

            notice.Name = txtName.Text;
            //if (ddlCategory.SelectIndex > 0 && ddlCategory.SelectId != null)
            //{
            //    notice.CategoryId = ddlCategory.SelectId.Value;
            //}

            if (ddlSignificant.SelectedIndex > 0)
            {
                notice.Significant = ddlSignificant.SelectedItem.Text;
            }

            //notice.Accepter = txtAccepter.Value;

            if (txtPublishDate.Text.Length > 0)
            {
                notice.PublishDate = DateTime.Parse(txtPublishDate.Text);
            }
            if (txtPublishDateEnd.Text.Length > 0)
            {
                notice.PublishDateEnd = DateTime.Parse(txtPublishDateEnd.Text);
            }
            //notice.CloseDate = txtCloseDate.Text;
            //notice.Profile = txtProfile.Text;

            odsNotice.SelectParameters.Clear();
            odsNotice.SelectParameters.Add("whereClause", notice.FilterExpression);

            //odsNotice.SelectParameters["whereClause"].DefaultValue = notice.FilterExpression;
        }
    }
}
